import '../../config/service_url.dart';

class User {
  final String username;
  final String? password;
  final String nickname;
  final String? avatar;
  final int gender;
  final String description;
  final int coin;
  final int vip;
  final int state;
  final int role;
  final String createDate;
  final String? deleteDate; // 可以为 null
  final int uid;

  User({
    required this.username,
    this.password,
    required this.nickname,
    this.avatar,
    required this.gender,
    required this.description,
    required this.coin,
    required this.vip,
    required this.state,
    required this.role,
    required this.createDate,
    this.deleteDate,
    required this.uid,
  });

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      username: json['username'],
      password: json['password'],
      nickname: json['nickname'],
      avatar: json['avatar'],
      gender: json['gender'],
      description: json['description'],
      coin: json['coin'],
      vip: json['vip'],
      state: json['state'],
      role: json['role'],
      createDate: json['createDate'],
      deleteDate: json['deleteDate'],
      uid: json['uid'],
    );
  }
}

class Video {
  final String title;
  final double duration;
  final int mcId;
  final List<String>? tags; // 可能为 null
  final String description;
  final String coverUrl;
  final String videoUrl;
  final int play;
  final int status;
  final int danmu;
  final int good;
  final int bad;
  final int coin;
  final int collect;
  final int comment;
  final String uploadDate;
  final String? deleteDate; // 可以为 null
  final int vid;
  final int uid;

  Video({
    required this.title,
    required this.duration,
    required this.mcId,
    this.tags,
    required this.description,
    required this.coverUrl,
    required this.videoUrl,
    required this.play,
    required this.status,
    required this.danmu,
    required this.good,
    required this.bad,
    required this.coin,
    required this.collect,
    required this.comment,
    required this.uploadDate,
    this.deleteDate,
    required this.vid,
    required this.uid,
  });

  factory Video.fromJson(Map<String, dynamic> json) {
    return Video(
      title: json['title'],
      duration: json['duration'],
      mcId: json['mcId'],
      tags: json['tags'] != null
          ? (json['tags'] is String
          ? [json['tags']] // 如果是字符串，则将其转换为列表
          : List<String>.from(json['tags'])) // 如果是列表，则直接转换
          : null, // 如果 tags 为 null
      description: json['description'],
      coverUrl: '$minioStartUrl/${json['coverUrl']}', // 拼接 coverUrl
      videoUrl: json['videoUrl'],
      play: json['play'],
      status: json['status'],
      danmu: json['danmu'],
      good: json['good'],
      bad: json['bad'],
      coin: json['coin'],
      collect: json['collect'],
      comment: json['commment'],
      uploadDate: json['uploadDate'],
      deleteDate: json['deleteDate'],
      vid: json['vid'],
      uid: json['uid'],
    );
  }
}

class RecommendVideoItemInfo {
  final User user;
  final Video video;
  final dynamic category; // 可以是任何类型

  RecommendVideoItemInfo({
    required this.user,
    required this.video,
    this.category,
  });

  factory RecommendVideoItemInfo.fromJson(Map<String, dynamic> json) {
    return RecommendVideoItemInfo(
      user: User.fromJson(json['user']),
      video: Video.fromJson(json['video']),
    );
  }
}